package com.ch.consumer.message.stream;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;

/**
 * @author cj-ch
 * @date 2018/4/26 上午11:52
 */
@EnableBinding(value = {
        StreamBindInputChannel.class,
        StreamBindOutputChannel.class})
public class StreamMessage {

    final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ObjectMapper objectMapper;

    @StreamListener(value = "my-input-channel")
    public void consumer(Object payload){
        try {
            System.out.println(payload.getClass().getName());
            logger.info("我接收到数据:{}" ,objectMapper.writeValueAsString(payload));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

}
